import { QXEvent } from 'qx-util';
import { IChatItem } from './interface';
/**
 * @description odoo聊天全局工具类
 * @export
 * @class OdooChatUtil
 */
export class OdooChatUtil {
  /**
   * @description 事件监听器
   * @protected
   * @memberof OdooChatUtil
   */
  protected evt: QXEvent<{ add: (data: IChatItem) => void }> = new QXEvent();

  /**
   * @description 添加聊天
   * @param {IChatItem} chat
   * @memberof OdooChatUtil
   */
  addChat(chat: IChatItem): void {
    this.evt.emit('add', chat);
  }

  /**
   * @description 订阅添加
   * @param {(data: IChatItem) => void} callback
   * @memberof OdooChatUtil
   */
  onAdd(callback: (data: IChatItem) => void): void {
    this.evt.on('add', callback);
  }

  /**
   * @description 取消订阅
   * @param {(data: IChatItem) => void} callback
   * @memberof OdooChatUtil
   */
  offAdd(callback: (data: IChatItem) => void): void {
    this.evt.off('add', callback);
  }
}

export const odooChatUtil = new OdooChatUtil();
